package cn.kgc.springcloud2038.order80.controller;

import cn.kgc.springcloud2038.api.pojo.CommonResult;
import cn.kgc.springcloud2038.api.pojo.Payment;
import cn.kgc.springcloud2038.order80.service.PaymentFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class OrderFeignController {
    @Resource
    private PaymentFeignService paymentFeignService;

//    @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod",commandProperties = {
//            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")
//    })
    @GetMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
    {
        return paymentFeignService.getPaymentById(id);
    }

//    public CommonResult<Payment> paymentTimeOutFallbackMethod(@PathVariable("id") Long id)
//    {
//        return new CommonResult<>(500,"降级……",null);
//    }

    @PostMapping(value = "/payment/create")
    public CommonResult create(@RequestBody Payment payment){
        return paymentFeignService.create(payment);
    }
}
